package com.mtsmda.bookjava7.chapter11.collectionEx.listEx;

import java.util.ArrayList;
import java.util.List;

public class ArrayListDemo {

	public static void main(String[] args) {
		String name = new String("Name");
		List<String> strings = new ArrayList<String>();
		strings.add("Hello");
		strings.add(name);
		strings.add(name + name);
		System.out.println(strings.size());

		System.out.println(strings.contains(name));
		System.out.println(strings.contains(15));
		// strings.remove(2);
		System.out.println(strings.size());
		for (int i = 0; i < strings.size(); i++) {
			strings.remove(i);
		}

		System.out.println("end - " + strings.size());

		System.out.println("----- new -----");

		ArrayList<String> list = new ArrayList<>(20);
		list.ensureCapacity(50);
		System.out.println("list.size() - " + list.size());
		for (int i = 0; i < 25; i++) {
			list.add("element #" + i);
		}

		list.trimToSize();
		System.out.println("list.size() - " + list.size());
		Object[] array = list.toArray();

		for (Object object : array) {
			if (object instanceof String) {
				System.out.print(object + "\t");
			}
		}

		String[] strings2 = new String[30];
		String[] array2 = list.toArray(strings2);
		strings2 = list.toArray(strings2);
		System.out.println();
		System.out.println(array2.length);
	}

}